<template>
  <div class="auto">
    <p class="zione">调查问卷</p>
    <div class="center">
      <div>
        <span class="span1">手机号：</span>
        <el-input class="ipt1" v-model="ruleForm.userName" @blur="blur" type="text" />
        <span v-if="dis" class="zi1">手机格式错误!!!</span>
      </div>

      <br />

      <div>
        <span class="span2">密码：</span>
        <el-input class="ipt1" show-password v-model="ruleForm.password" type="text" />
      </div>

      <button class="btn" @click="op">登录</button>
    </div>
    <div @click="jump" class="ce">没有账号？立即注册</div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        userName: "",
        password: ""
      ,
      },
      dis:false,
      menu: "",
    };
  },
  methods: {
    async op() {
      let formData = new FormData();
      for (const key in this.ruleForm) {
        formData.append(key, this.ruleForm[key]);
      }
      console.log(formData);
      let res = await this.$http.post("/user/login", formData);

      this.$store.commit("userinfo", res.data);
      console.log(res);
      if (res.code == 1001) {
        this.$router.push("/index/chi/1");
      }else if(res.code==4001){
        this.$message.error('手机格式错误');
      }else if(res.code==5001){
        this.$message.error('用户不存在或密码输入错误');
      }
    },
    jump(){
      this.$router.push("/ce");
    },
    blur(){
      var p=/^1\d{10}$/
      this.dis= !p.test(this.ruleForm.userName)
    }
  },
};
</script>

<style scoped>
*{
  margin: 0;
  padding: 0;
}
.auto {
  width: 500px;
  height: 300px;
  /* border: 1px solid black; */
  margin: 250px auto;
  box-shadow: -1px -1px 5px #000;
  overflow: hidden;
  position: relative;
}
.zi1{
  position: absolute;
  top: 100px;
  right: 35px;

  display: inline-block;
  color: red;
  font-size: 12px;
}
.zione {
  display: block;
  text-align: center;
  font-size: 20px;
  margin-top: 25px;
  color: #fb6d49;
  font-weight: bold;
}
.center {
  width: 262px;
  height: 150px;
  /* border: 1px solid red; */
  margin: 45px auto;
}
.ipt1 {
  width: 200px;
  height: 25px;
}
.span1 {
  font-size: 15px;
  color: #fb6d49;
}
.span2 {
  font-size: 15px;
  padding-right: 15px;
  color: #fb6d49;
}
.btn {
  width: 204px;
  height: 30px;
  display: block;
  margin: 25px 0 0 57px  ;
  background: #fb6d49;
  color: #fff;
  font-size: 10px;
  /* letter-spacing: 50px;
  text-align: center; */
  cursor: pointer;
}
.ce{
  position: absolute;
  right: 40px;
  bottom:35px;
  cursor: pointer;
  font-size: 12px;
}
.el-input__inner{
  height: 38px;
}
@media screen and (max-width:768px) {
  .auto{
    width: 100%;
     margin-top: 200px;
  }
}
</style>